package com.penghk.springbootdemo.controller;

import com.penghk.springbootdemo.entity.People;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class DemoRestController {

    @RequestMapping(value = "/getJson" , produces = {"application/json;charset=utf-8"})
    public People getPeopleJson() {
        return new People(1L,"tom" , 23);
    }

    @RequestMapping(value = "/getXml" , produces = {"application/xml;charset=utf-8"})
    public People getPeopleXml() {
        return new People(1L,"tom" , 23);
    }

    @RequestMapping(value = "/getExe" , produces = {"application/json;charset=utf-8"})
    public People getExe(Model model , @ModelAttribute("msg") String msg) throws Exception {
        System.out.println(msg);
        throw new Exception("eoor");
    }

    /**
     * 代码修改，重新编译　依赖devtools 进行热部署
     * @return
     */
    @RequestMapping(value = "/getJson2" , produces = {"application/json;charset=utf-8"})
    public People getPeopleJson2() {
        System.out.println("");
        return new People(1L,"tom" , 23);
    }

    @RequestMapping(value = "/getJson3" , produces = {"application/json;charset=utf-8"})
    public People getPeopleJson3() {
        System.out.println("hello");
        return new People(1L,"tom" , 23);
    }



    @RequestMapping(value = "/getparams" , params = {"fn=100012"})
    public void getParams() {
        System.out.println("getParams");
    }


    @PostMapping(value = "/getparams" ,params = {"fn=100012"})
    public String getPost() {
        return "{\"name\":\"tom\"}";
    }
}
